home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / perl / mac-perl / mcprl402.bin / Perl_src / handy.h < prev    next >
Text File  |  1992-09-27  |  5KB  |  156 lines

  1. /* $RCSfile: handy.h,v $$Revision: 4.0.1.4 $$Date: 92/06/08 13:23:17 $
  2.  *
  3.  *    Copyright (c) 1991, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  * $Log:    handy.h,v $
  9.  * Revision 4.0.1.4  92/06/08  13:23:17  lwall
  10.  * patch20: isascii() may now be supplied by a library routine
  11.  * patch20: Perl now distinguishes overlapped copies from non-overlapped
  12.  * 
  13.  * Revision 4.0.1.3  91/11/05  22:54:26  lwall
  14.  * patch11: erratum
  15.  * 
  16.  * Revision 4.0.1.2  91/11/05  17:23:38  lwall
  17.  * patch11: prepared for ctype implementations that don't define isascii()
  18.  * 
  19.  * Revision 4.0.1.1  91/06/07  11:09:56  lwall
  20.  * patch4: new copyright notice
  21.  * 
  22.  * Revision 4.0  91/03/20  01:22:15  lwall
  23.  * 4.0 baseline.
  24.  * 
  25.  */
  26.  
  27. #ifdef NULL
  28. #undef NULL
  29. #endif
  30. #ifndef I286
  31. #  define NULL 0
  32. #else
  33. #  define NULL 0L
  34. #endif
  35. #define Null(type) ((type)NULL)
  36. #define Nullch Null(char*)
  37. #define Nullfp Null(FILE*)
  38.  
  39. #ifdef UTS
  40. #define bool int
  41. #else
  42. #define bool char
  43. #endif
  44.  
  45. #ifdef TRUE
  46. #undef TRUE
  47. #endif
  48. #ifdef FALSE
  49. #undef FALSE
  50. #endif
  51. #define TRUE (1)
  52. #define FALSE (0)
  53.  
  54. #define Ctl(ch) (ch & 037)
  55.  
  56. #define strNE(s1,s2) (strcmp(s1,s2))
  57. #define strEQ(s1,s2) (!strcmp(s1,s2))
  58. #define strLT(s1,s2) (strcmp(s1,s2) < 0)
  59. #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
  60. #define strGT(s1,s2) (strcmp(s1,s2) > 0)
  61. #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
  62. #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
  63. #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
  64.  
  65. #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
  66. #define isALNUM(c) (isalpha(c) || isdigit(c) || c == '_')
  67. #define isALPHA(c) isalpha(c)
  68. #define isSPACE(c) isspace(c)
  69. #define isDIGIT(c) isdigit(c)
  70. #define isUPPER(c) isupper(c)
  71. #define isLOWER(c) islower(c)
  72. #else
  73. #define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
  74. #define isALPHA(c) (isascii(c) && isalpha(c))
  75. #ifdef macintosh
  76. #define isSPACE(c) ((isascii(c) && isspace(c)) || c == '\312')
  77. #else
  78. #define isSPACE(c) (isascii(c) && isspace(c))
  79. #endif
  80. #define isDIGIT(c) (isascii(c) && isdigit(c))
  81. #define isUPPER(c) (isascii(c) && isupper(c))
  82. #define isLOWER(c) (isascii(c) && islower(c))
  83. #endif
  84.  
  85. #define MEM_SIZE unsigned int
  86.  
  87. /* Line numbers are unsigned, 16 bits. */
  88. typedef unsigned short line_t;
  89. #ifdef lint
  90. #define NOLINE ((line_t)0)
  91. #else
  92. #define NOLINE ((line_t) 65535)
  93. #endif
  94.  
  95. #ifndef lint
  96. #ifndef LEAKTEST
  97. #ifndef safemalloc
  98. char *safemalloc();
  99. char *saferealloc();
  100. void safefree();
  101. #endif
  102. #ifndef MSDOS
  103. #define New(x,v,n,t)  (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
  104. #define Newc(x,v,n,t,c)  (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
  105. #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
  106.     memzero((char*)(v), (n) * sizeof(t))
  107. #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  108. #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  109. #else
  110. #define New(x,v,n,t)  (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
  111. #define Newc(x,v,n,t,c)  (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
  112. #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
  113.     memzero((char*)(v), (n) * sizeof(t))
  114. #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
  115. #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
  116. #endif /* MSDOS */
  117. #define Safefree(d) safefree((char*)d)
  118. #define Str_new(x,len) str_new(len)
  119. #else /* LEAKTEST */
  120. char *safexmalloc();
  121. char *safexrealloc();
  122. void safexfree();
  123. #define New(x,v,n,t)  (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
  124. #define Newc(x,v,n,t,c)  (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
  125. #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
  126.     memzero((char*)(v), (n) * sizeof(t))
  127. #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  128. #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  129. #define Safefree(d) safexfree((char*)d)
  130. #define Str_new(x,len) str_new(x,len)
  131. #define MAXXCOUNT 1200
  132. long xcount[MAXXCOUNT];
  133. long lastxcount[MAXXCOUNT];
  134. #endif /* LEAKTEST */
  135. #ifndef RESOLVE_MAC_CONFLICTS
  136. #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
  137. #endif
  138. #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
  139. #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
  140. #else /* lint */
  141. #define New(x,v,n,s) (v = Null(s *))
  142. #define Newc(x,v,n,s,c) (v = Null(s *))
  143. #define Newz(x,v,n,s) (v = Null(s *))
  144. #define Renew(v,n,s) (v = Null(s *))
  145. #define Move(s,d,n,t)
  146. #define Copy(s,d,n,t)
  147. #define Zero(d,n,t)
  148. #define Safefree(d) d = d
  149. #endif /* lint */
  150.  
  151. #ifdef STRUCTCOPY
  152. #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
  153. #else
  154. #define StructCopy(s,d,t) Copy(s,d,1,t)
  155. #endif
  156.